#include <stdio.h>

int main()
{
    FILE *fp = fopen("test.txt", "w+");
    if (fp == NULL)
    {
        perror("open file failed\n");
        return -1;
    }

    fwrite("hello world\n", 12, 1, fp);

    fseek(fp, 0, SEEK_SET);
    char buf[1024] = {0};
    fread(buf, 12, 1, fp);
    printf("%s\n", buf);

    fclose(fp);
}